
/*
 *   Copyright (C) 2020 ZPD Ltd. All rights reserved.
 *   
 *   FileName:cglog.h
 *
 *   Author:LiuHongliang
 *
 *   Create:2020年06月10日
 *
 *   Brief:
 *
 */
#ifndef _CLOG_H_
#define _CLOG_H_

#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

#define LOG_DEBUG //enable log debug

#define MAX_FILE_LEN (5 * 1024 * 1024)

typedef enum _LOG_LEVEL {
    EM_LOG_FATAL = 0,
    EM_LOG_ERROR,
    EM_LOG_WARN,
    EM_LOG_INFO,
    EM_LOG_DEBUG,
    EM_LOG_TRACE
}EM_LOG_LEVEL;

void clog_exit(void);
int  clog_init(char *path);
void clog_set_log_size(int max_size);
void clog_set_log_level(int log_level);
void clog_set_log_stdout(bool en);
void clog_log(int level, const char *func, int line, const char *fmt, ...);

#define EM_LOG(level, fmt, args...)  clog_log(level, __func__, __LINE__, fmt, ##args)

#ifdef LOG_DEBUG

#define DEBUG(fmt, args...)  \
        do {\
                clog_log(EM_LOG_DEBUG, __func__, __LINE__, fmt, ##args); \
        }while(0)
#define INFO(fmt, args...)  \
        do {\
                clog_log(EM_LOG_INFO, __func__, __LINE__, fmt, ##args); \
        }while(0)

#define WARN(fmt, args...)  \
        do {\
                clog_log(EM_LOG_WARN, __func__, __LINE__, fmt, ##args); \
        }while(0)

#define ERROR(fmt, args...)  \
        do {\
                clog_log(EM_LOG_ERROR, __func__, __LINE__, fmt, ##args); \
        }while(0)

#define FATAL(fmt, args...)  \
        do {\
                clog_log(EM_LOG_FATAL, __func__, __LINE__, fmt, ##args); \
        }while(0)

#else

#define DEBUG(fmt, args...) \
        do {\
        }while(0)

#define INFO(fmt, args...) \
        do {\
        }while(0)

#define WARN(fmt, args...) \
        do {\
        }while(0)

#define ERROR(fmt, args...) \
        do {\
        }while(0)

#define FATAL(fmt, args...) \
        do {\
        }while(0)

#endif

#ifdef __cplusplus
}
#endif

#endif //CLOG_H_
